package io.jt808.proto.cmd;

import io.norland.buffer.AutoBuffer;
import io.norland.annotations.Proto;
import io.norland.proto.IProto;
import lombok.Data;

/**
 * 录音开始命令
 */
@Proto("8804")
@Data
public class JT8804 implements IProto {
    /**
     * 录音命令
     */
    private byte recordCommand;
    /**
     * 录音时间
     */
    private short recordTime;
    /**
     * 保存标志
     */
    private byte storeFlag;
    /**
     * 音频采样率
     */
    private byte samplingRate;


    public final byte[] writeToBytes() {
        AutoBuffer buffer = new AutoBuffer();
        buffer.writeByte(recordCommand);
        buffer.writeShort(recordTime);
        buffer.writeByte(storeFlag);
        buffer.writeByte(samplingRate);
        return buffer.array();
    }

    public final void readFromBuf(AutoBuffer buffer) {
        recordCommand = buffer.readByte();
        recordTime = buffer.readShort();
        storeFlag = buffer.readByte();
        samplingRate = buffer.readByte();
    }

//    public static void main(String[] args) {
//        byte[] bytes = new byte[]{
//                0x01,
//                0x01, 0x0F,
//                0x01,
//                0x00
//        };
//        JT8804 jt8600 = new JT8804();
//        jt8600.readFromBuf(new AutoBuffer(bytes));
//        System.out.println(new String(bytes).equals(new String(jt8600.writeToBytes())));
//    }
}